﻿using BLL;
using Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Windows.Forms;

namespace Teacher
{
    public partial class Result_form : Form
    {
        List<Models.StuGroup> all_groups;
        List<Models.StuGroup> your_groups;
        public Result_form()
        {
            InitializeComponent();
        }

        private void Result_form_Load(object sender, EventArgs e)
        {
            try
            {
                B_Group b_Group = new B_Group();

                all_groups = b_Group.GetList();
                group_list.DataSource = all_groups;

                your_groups = all_groups.Where(g => g.teacher_id == LogInfo.teacher.teacher_id).ToList();
                your_Groups.DataSource = your_groups;
            }
            catch
            {
                MessageBox.Show("信息读取失败!");
            }
        }

        private void your_Groups_MouseClick(object sender, MouseEventArgs e)
        {
            try
            {
                if (your_Groups.Rows.Count == 0) 
                    return;

                if (your_Groups.CurrentCell == null)
                    return;

                int idx = your_Groups.CurrentCell.RowIndex;
                BLL.B_Student b_Student = new BLL.B_Student();

                var stus = b_Student.GetList(your_groups[idx]);
                Group_members.DataSource = stus;
                Disp_Group_info(your_groups[idx]);
            }
            catch
            {
                MessageBox.Show("未知错误!");
            }
        }

        private void group_list_MouseClick(object sender, MouseEventArgs e)
        {
            try
            {
                if (group_list.CurrentCell == null) return;

                int idx = group_list.CurrentCell.RowIndex;

                BLL.B_Student b_Student = new BLL.B_Student();
                var stus = b_Student.GetList(all_groups[idx]);

                Group_members.DataSource = stus;

                Disp_Group_info(all_groups[idx]);
            }
            catch
            {
                MessageBox.Show("未知错误!");
            }
        }

        private void Disp_Group_info(Models.StuGroup stu_Group)
        {
            try
            {
                Group_info.Text = stu_Group.project_info;
                Group_name.Text = stu_Group.group_name;
                Project_name.Text = stu_Group.project_name;
            }
            catch
            {
                MessageBox.Show("信息读取失败!");
            }
        }

        private void your_Groups_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void Project_name_TextChanged(object sender, EventArgs e)
        {

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }
    }
}
